
package com.joysuch.wwyt.bp.controller;

import javax.validation.Valid;

import com.joysuch.wwyt.bp.BpSystemVideoSearchBean;
import com.joysuch.wwyt.bp.bean.BpSystemVideoAddBean;
import com.joysuch.wwyt.bp.service.BpSystemVideoService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.common.util.PageDataUtils;
import com.joysuch.wwyt.core.exception.ApiBusinessException;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "摄像头管理")
@RequestMapping("/bp/system-video")
public class BpSystemVideoController {

    @Autowired
    private BpSystemVideoService systemVideoService;

    @GetMapping("/page")
    public ResultBean list(Pageable page, BpSystemVideoSearchBean condition) {
        page = PageDataUtils.addOrderByDesc(page, "id");
        Page<BpSystemVideoAddBean> list = systemVideoService.list(page,condition);
        return ResultBean.pageData(list);
    }

    @PostMapping("/add")
    public ResultBean add(@RequestBody @Valid BpSystemVideoAddBean bpSystemVideo) {
        systemVideoService.add(bpSystemVideo);
        return ResultBean.defaultSuccessResult();
    }

    @PostMapping("/update")
    public ResultBean update(@RequestBody @Valid BpSystemVideoAddBean bpSystemVideo) {
        systemVideoService.update(bpSystemVideo);
        return ResultBean.defaultSuccessResult();
    }

    @PostMapping("/delete")
    public ResultBean delete(Long id) {
        systemVideoService.delete(id);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("/getById")
    public ResultBean getById(Long id) {
        try {
            return ResultBean.wrapSuccessfulResult(systemVideoService.getByid(id));
        } catch (ApiBusinessException e) {
            return ResultBean.fail(e.getCode(),e.getMessage());
        }
    }

}
